jGo.sound = function($){
    $.sound_count = 1;
    var methods = {
        fc_sound: function fc_sound(user_settings) {
            var self = $(this);
		    var movie = null;
		    var getMovie = function(self,isPlaying){
				if(isPlaying!= null){
					self.data("fc_sound.isPlaying", isPlaying);
				}
				if(movie){
					return movie;
				}else{
					movie = jGo.flash.getFlash(self.data("fc_sound.settings").id);
					return movie;
				}
		    };
            var settings = {
                quality: 'high',
                events: {
            		createSound: function(evt, url) {
                		var id = getMovie($(this),true).createSound(url);
                		$(this).data("fc_last_id", id);
             		},
                    play: function(evt, id) {
                        getMovie($(this),true).playit(id);
                    },
                    pause: function(evt, id) {
                        getMovie($(this),false).pauseit(id);
                    },
                    stop: function(evt, id) {
                        getMovie($(this),false).stopit(id);
                    },
                    volume: function(evt, id, vol) {
                        if(vol > 100) {
                            vol = vol - 100;
                        }
                        getMovie($(this)).setVolume(id,vol);
                    },
                    error: function(evt, err) {
                        alert(err.msg);
                    }
                }
            };

            if(self.data("fc_sound.settings")) {
                settings = self.data("fc_sound.settings");
            }

            settings = $.extend(user_settings, settings);
				
            if(!self.data("fc_sound")) {
                settings.id = 'FCSoundPlayer' + $.sound_count;
				var html = jGo.flash.writeFlash('FCSoundPlayer',$.sound_count, '10px','10px', settings.basedir, '#000000', 'transparent','id=' + settings.id);

                for(var event in settings.events) {
                    var evt = "fc_sound." + event;
                    self.unbind(evt);
                    self.bind(evt, settings.events[event]);
                }
                
                //html='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="10px" height="10px" id="Player1Object"> <param name=movie value="/Player.swf" /><param name="allowScriptAccess" value="always" /><param name="align" value="left" /><param name="wmode" value="transparent" /><param name="flashvars" value="id=Player1" /><param name="quality" value="high" /><param name=swLiveConnect value="true"><embed id="Player1Embed"src="/Player.swf" allowFullScreen="true" quality="high" wmode="transparent" flashvars="id=Player1" width="10px" height="10px" align="left" allowScriptAccess="always" type="application/x-shockwave-flash" swLiveConnect="true" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
                	
                self[0].innerHTML=html;
                self.data("fc_sound", true);

                $.sound_count++;
            }

            self.data("fc_sound.settings", settings);
            $(this).data("fc_sound.isPlaying", false);

            if(settings.file) {
                var delayed = function() {
                    self.load(settings.file);
                };
                setTimeout(delayed, 250);
            }
            
            return self;
        },
        fc_createSound: function(url) {
            var self = $(this);
            if(self.data("fc_sound")) {
                self.trigger("fc_sound.createSound", url);
            }
        },
        fc_getLastId: function() {
            var self = $(this);
            return self.data("fc_last_id");
        },
        fc_play: function(id) {
            var self = $(this);
            if(self.data("fc_sound")) {
                self.trigger("fc_sound.play", id);
            }
        },
        fc_pause: function(id) {
            var self = $(this);
            if(self.data("fc_sound")) {
                self.trigger("fc_sound.pause", id);
            }
        },
        fc_stop: function(id) {
            var self = $(this);
            if(self.data("fc_sound")) {
                self.trigger("fc_sound.stop", id);
            }
        },
        fc_volume: function(vol) {
            var self = $(this);
            if(self.data("fc_sound")) {
                self.trigger("fc_sound.volume", id, vol);
            }
        }
    };
    $.each(methods, function(i) {
        $.fn[i] = this;
    });
};